package game;

public class Street extends Ownable{
	private int 			group;
	private int[] 		rent;
	private int 			property;
	private int			propertyPrice;
	private boolean 	mortgage = false;

	//Konstruktør med kendte variabler. Kalder fra Super-klasse
	public Street(String name, int group, int price, int[] rent, int property){
		this.name = name;
		this.group = group;
		this.rent = rent;
		this.propertyPrice = property;
		
		setPrice(price);
	}
	
	public void buyProperty(int numProperty){
		if( (getOwner().getAccount().getPoint() >= propertyPrice) && (property + numProperty < 6) && (numProperty > 0)){
			property = property + numProperty;
			getOwner().getAccount().addPoints(-(propertyPrice * numProperty));
			
		}
	}
	
	public void sellProperty(int numProperty) {		
		
		if ((property >= numProperty) && (property > 0)){
			property = property - numProperty;
			getOwner().getAccount().addPoints ( (propertyPrice * numProperty) / 2 );
		}
	}

	public void landOnField(Player player){
		super.landOnField(player);
		
	}

	//Metode til at hente variablen group
	public int getGroup()
	{
		return group;
	}
	
	public int getProperty()
	{
		return property;
	}
	
	public int getPropertyPrice()
	{
		return propertyPrice;
	}
	
	
	//Skal give leje værdien når der landes på feltet
	public int getRent() {
		int rentToPay;
		int[] groupsOwned = Board.availableGroups(this.getOwner());
		boolean OwnerOfGroup = false;
			
		for(int i = 0; i < groupsOwned.length; i++) {
			if(groupsOwned[i] == group){
				OwnerOfGroup = true;
			}
		} 
			
		if (OwnerOfGroup == true) {
			if (property > 0){
				rentToPay = rent[property-1];
			} else {
				rentToPay = rent[0] * 2;
			}
		} else {
			rentToPay = rent[0];
		}
		if (getMortgage() == true)
		{
			rentToPay = 0;
		}
			
		return rentToPay;
	}
		
}